﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit_games.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Events.edit_game_dhbc" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <% int id = int.Parse(Request.QueryString["id"]);
        int player = int.Parse(Request.QueryString["player"]);
        int events = int.Parse(Request.QueryString["event"]);
        string time = Request.QueryString["time"];
        string added = Request.QueryString["added"];
        string scores = Request.QueryString["scores"];
        if (id == 1)
        {
            var get_role = new TblEventGameController().FetchAll().Single(x => x.Id == id);
            var get_event = new TblEventController().FetchAll().Single(x => x.Id == events);
            var get_plan = new TblEventPlanController().FetchAll().Single(x => x.EventId == events && x.GamesType == id);

    %>
    <div style="width: 80%" class="w3-modal-content w3-animate-top w3-card-8 w3-display-container">
        <header class="w3-center w3-padding w3-large w3-teal"><%=get_role.Name.ToString().ToUpper() %></header>
        <div class="w3-row w3-padding">
            <label class="w3-col l1">Luật chơi</label><textarea disabled="disabled" class="game-text w3-col l11 w3-light-grey"><%=get_role.Role %></textarea>
        </div>
        <div class="w3-row w3-padding w3-third">
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Thời gian</label><input <%if (time == "")
                                                              {%>value="0"
                    <%}
                                                              else
                                                              { %>
                    value="<%=int.Parse(time) %>" <%} %> type="number" min="0" class="edit_game_time game-text w3-col l8 w3-light-grey" /><span class="w3-col l1 w3-center">Giây</span>
            </div>
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Điểm số</label><div class="w3-col l9">
                    <%if (scores == "")
                        { %>
                    <%for (int i = 1; i <= player; i++)
                        {%>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2"><%=i %>.</span><input value="0" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%}
                        }
                        else
                        {
                            string[] split = scores.Split(',');
                    %>
                    <%for (int i = 1; i <= player; i++)
                        { %>
                    <div class="w3-row w3-padding-bottom">
                        <span class="w3-col l2"><%=i %>.</span><input <%if (i > split.Length)
                                                                   { %>value="0"
                            <%}
                                                                   else
                                                                   { %>value="<%=split[i - 1] %>"
                            <%} %> type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span>
                    </div>
                    <%} %>
                    <%} %>
                </div>
            </div>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_add_question_form">
                    <tr class="w3-teal">
                        <td>Câu hỏi đang có</td>
                    </tr>
                    <%if (added == "")
                        {
                            var get_game = from p in new TblDHBCQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblDHBCQuestion question in get_game)
                            {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                        }
                        else
                        {
                            string[] split = added.Split(',');
                            var get_game = from p in new TblDHBCQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblDHBCQuestion question in get_game)
                            {
                                if (this.check_game(split, question.Id) == false)
                                {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                            }
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_added_question_form" class="w3-row">
                    <tr class="w3-teal w3-row">
                        <td>Câu hỏi đã thêm</td>
                    </tr>
                    <%if (added != "")
                        {
                            string[] split = added.Split(',');
                            for (int i = 0; i < split.Length - 1; i++)
                            {
                                var get_game = new TblDHBCQuestionController().FetchAll().Single(x => x.Id == int.Parse(split[i]));
                    %>
                    <tr class="game_added" id="add_1_<%=get_game.Id %>">
                        <td class="w3-hide"><%=get_game.Id %></td>
                        <td class="w3-col l11"><%=get_game.Name %></td>
                        <td class="w3-col l1"><i onclick="cancel_add_question(this.parentElement.parentElement.id)" class="fa fa-trash"></i></td>
                    </tr>
                    <%}
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-center">
            <a onclick="btn_add_game(1)" class="w3-btn w3-teal"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            <a onclick="$('#add_game_modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Huỷ</a>
        </div>
    </div>
    <%} %>

    <%if (id == 2)
        {
            var get_role = new TblEventGameController().FetchAll().Single(x => x.Id == id);
            var get_event = new TblEventController().FetchAll().Single(x => x.Id == events);
            var get_plan = new TblEventPlanController().FetchAll().Single(x => x.EventId == events && x.GamesType == id);

    %>
    <div style="width: 80%" class="w3-modal-content w3-animate-top w3-card-8 w3-display-container">
        <header class="w3-center w3-padding w3-large w3-teal"><%=get_role.Name.ToString().ToUpper() %></header>
        <div class="w3-row w3-padding">
            <label class="w3-col l1">Luật chơi</label><textarea disabled="disabled" class="game-text w3-col l11 w3-light-grey"><%=get_role.Role %></textarea>
        </div>
        <div class="w3-row w3-padding w3-third">
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Thời gian</label><input <%if (time == "")
                                                              {%>value="0"
                    <%}
                                                              else
                                                              { %>
                    value="<%=int.Parse(time) %>" <%} %> type="number" min="0" class="edit_game_time game-text w3-col l8 w3-light-grey" /><span class="w3-col l1 w3-center">Giây</span>
            </div>
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Điểm số</label><div class="w3-col l9">
                    <%if (scores == "")
                        { %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="0" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Sai</span><input value="0" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%}
                        else
                        {
                            int correct = 0, incorrect = 0;
                            string[] split = scores.Split(',');
                            if (split.Length - 1 < 2)
                                correct = int.Parse(split[0]);
                            else
                            {
                                correct = int.Parse(split[0]);
                                incorrect = int.Parse(split[1]);
                            }
                    %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="<%=correct %>" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Sai</span><input value="<%=incorrect %>" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%} %>
                </div>
            </div>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_add_question_form">
                    <tr class="w3-teal">
                        <td>Câu hỏi đang có</td>
                    </tr>
                    <%if (added == "")
                        {
                            var get_game = from p in new TblReverseQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblReverseQuestion question in get_game)
                            {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                        }
                        else
                        {
                            string[] split = added.Split(',');
                            var get_game = from p in new TblReverseQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblReverseQuestion question in get_game)
                            {
                                if (this.check_game(split, question.Id) == false)
                                {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                            }
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_added_question_form" class="w3-row">
                    <tr class="w3-teal w3-row">
                        <td>Câu hỏi đã thêm</td>
                    </tr>
                    <%if (added != "")
                        {
                            string[] split = added.Split(',');
                            for (int i = 0; i < split.Length - 1; i++)
                            {
                                var get_game = new TblReverseQuestionController().FetchAll().Single(x => x.Id == int.Parse(split[i]));
                    %>
                    <tr class="game_added" id="add_1_<%=get_game.Id %>">
                        <td class="w3-hide"><%=get_game.Id %></td>
                        <td class="w3-col l11"><%=get_game.Name %></td>
                        <td class="w3-col l1"><i onclick="cancel_add_question(this.parentElement.parentElement.id)" class="fa fa-trash"></i></td>
                    </tr>
                    <%}
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-center">
            <a onclick="btn_add_game(<%=id %>)" class="w3-btn w3-teal"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            <a onclick="$('#add_game_modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Huỷ</a>
        </div>
    </div>
    <%} %>

    <%if (id == 3)
        {
            var get_role = new TblEventGameController().FetchAll().Single(x => x.Id == id);
            var get_event = new TblEventController().FetchAll().Single(x => x.Id == events);
            var get_plan = new TblEventPlanController().FetchAll().Single(x => x.EventId == events && x.GamesType == id);

    %>
    <div style="width: 80%" class="w3-modal-content w3-animate-top w3-card-8 w3-display-container">
        <header class="w3-center w3-padding w3-large w3-teal"><%=get_role.Name.ToString().ToUpper() %></header>
        <div class="w3-row w3-padding">
            <label class="w3-col l1">Luật chơi</label><textarea disabled="disabled" class="game-text w3-col l11 w3-light-grey"><%=get_role.Role %></textarea>
        </div>
        <div class="w3-row w3-padding w3-third">
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Thời gian</label><input <%if (time == "")
                                                              {%>value="0"
                    <%}
                                                              else
                                                              { %>
                    value="<%=int.Parse(time) %>" <%} %> type="number" min="0" class="edit_game_time game-text w3-col l8 w3-light-grey" /><span class="w3-col l1 w3-center">Giây</span>
            </div>
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Điểm số</label><div class="w3-col l9">
                    <%if (scores == "")
                        { %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="0" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%}
                        else
                        { %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="<%=int.Parse(scores.Split(',')[0]) %>" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%} %>
                </div>
            </div>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_add_question_form">
                    <tr class="w3-teal">
                        <td>Câu hỏi đang có</td>
                    </tr>
                    <%if (added == "")
                        {
                            var get_game = from p in new TblVideoQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblVideoQuestion question in get_game)
                            {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                        }
                        else
                        {
                            string[] split = added.Split(',');
                            var get_game = from p in new TblVideoQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblVideoQuestion question in get_game)
                            {
                                if (this.check_game(split, question.Id) == false)
                                {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                            }
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_added_question_form" class="w3-row">
                    <tr class="w3-teal w3-row">
                        <td>Câu hỏi đã thêm</td>
                    </tr>
                    <%if (added != "")
                        {
                            string[] split = added.Split(',');
                            for (int i = 0; i < split.Length - 1; i++)
                            {
                                var get_game = new TblVideoQuestionController().FetchAll().Single(x => x.Id == int.Parse(split[i]));
                    %>
                    <tr class="game_added" id="add_1_<%=get_game.Id %>">
                        <td class="w3-hide"><%=get_game.Id %></td>
                        <td class="w3-col l11"><%=get_game.Name %></td>
                        <td class="w3-col l1"><i onclick="cancel_add_question(this.parentElement.parentElement.id)" class="fa fa-trash"></i></td>
                    </tr>
                    <%}
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-center">
            <a onclick="btn_add_game(<%=id %>)" class="w3-btn w3-teal"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            <a onclick="$('#add_game_modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Huỷ</a>
        </div>
    </div>
    <%} %>

    <%if (id == 4)
        {
            var get_role = new TblEventGameController().FetchAll().Single(x => x.Id == id);
            var get_event = new TblEventController().FetchAll().Single(x => x.Id == events);
            var get_plan = new TblEventPlanController().FetchAll().Single(x => x.EventId == events && x.GamesType == id);

    %>
    <div style="width: 80%" class="w3-modal-content w3-animate-top w3-card-8 w3-display-container">
        <header class="w3-center w3-padding w3-large w3-teal"><%=get_role.Name.ToString().ToUpper() %></header>
        <div class="w3-row w3-padding">
            <label class="w3-col l1">Luật chơi</label><textarea disabled="disabled" class="game-text w3-col l11 w3-light-grey"><%=get_role.Role %></textarea>
        </div>
        <div class="w3-row w3-padding w3-third">
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Thời gian</label><input <%if (time == "")
                                                              {%>value="0"
                    <%}
                                                              else
                                                              { %>
                    value="<%=int.Parse(time) %>" <%} %> type="number" min="0" class="edit_game_time game-text w3-col l8 w3-light-grey" /><span class="w3-col l1 w3-center">Giây</span>
            </div>
            <div class="w3-row w3-padding">
                <label class="w3-col l3">Điểm số</label><div class="w3-col l9">
                    <%if (scores == "")
                        { %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="0" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%}
                        else
                        { %>
                    <div class="w3-row w3-padding-bottom"><span class="w3-col l2">Đúng</span><input value="<%=int.Parse(scores.Split(',')[0]) %>" type="number" class="game-text edit_game_score w3-col l8 w3-light-grey" /><span class="w3-col l2 w3-center">Điểm</span></div>
                    <%} %>
                </div>
            </div>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_add_question_form">
                    <tr class="w3-teal">
                        <td>Câu hỏi đang có</td>
                    </tr>
                    <%if (added == "")
                        {
                            var get_game = from p in new TblCrossWordQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblCrossWordQuestion question in get_game)
                            {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                        }
                        else
                        {
                            string[] split = added.Split(',');
                            var get_game = from p in new TblCrossWordQuestionController().FetchAll() orderby p.Id descending select p;
                            foreach (TblCrossWordQuestion question in get_game)
                            {
                                if (this.check_game(split, question.Id) == false)
                                {
                    %>
                    <tr onclick="add_question(this.id)" id="add_1_<%=question.Id %>">
                        <td class="w3-hide"><%=question.Id %></td>
                        <td class="w3-col l11"><%=question.Name %></td>
                    </tr>
                    <%}
                            }
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-third" style="height: 250px; overflow: auto">
            <table class="volca-table w3-table w3-striped w3-bordered w3-white">
                <tbody id="tbl_added_question_form" class="w3-row">
                    <tr class="w3-teal w3-row">
                        <td>Câu hỏi đã thêm</td>
                    </tr>
                    <%if (added != "")
                        {
                            string[] split = added.Split(',');
                            for (int i = 0; i < split.Length - 1; i++)
                            {
                                var get_game = new TblCrossWordQuestionController().FetchAll().Single(x => x.Id == int.Parse(split[i]));
                    %>
                    <tr class="game_added" id="add_1_<%=get_game.Id %>">
                        <td class="w3-hide"><%=get_game.Id %></td>
                        <td class="w3-col l11"><%=get_game.Name %></td>
                        <td class="w3-col l1"><i onclick="cancel_add_question(this.parentElement.parentElement.id)" class="fa fa-trash"></i></td>
                    </tr>
                    <%}
                        } %>
                </tbody>
            </table>
        </div>
        <div class="w3-row w3-padding w3-center">
            <a onclick="btn_add_game(<%=id %>)" class="w3-btn w3-teal"><i class="fa fa-save"></i>&nbsp;Lưu</a>
            <a onclick="$('#add_game_modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Huỷ</a>
        </div>
    </div>
    <%} %>
</body>
</html>
